/*
 * Created on Nov 25, 2004
 *
 * To change the template for this generated file go to
 * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
 */
package fr.aliasource.obm.aliapool.pool;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.SQLWarning;
import java.sql.Statement;

/**
 * Delegate sur les statement crées par le pool pour assurer le suivi 
 * des ResultSet pas fermés
 * 
 * @author tom
 *
 */
public class StatementProxy
	extends AbstractStatementProxy
	implements Statement {

	private Statement ps;
	private ConnectionProxy cp;

	public StatementProxy(Statement ps, ConnectionProxy cp) {
		this.ps = ps;
		this.cp = cp;
		cp.addOpenStatement(this);
	}

	/**
	 * @throws java.sql.SQLException
	 */
	public void close() throws SQLException {
		ps.close();
		cp.closeStatement(this);
	}

	/**
	 * @param sql
	 * @throws java.sql.SQLException
	 */
	public void addBatch(String sql) throws SQLException {
		ps.addBatch(sql);
	}

	/**
	 * @throws java.sql.SQLException
	 */
	public void cancel() throws SQLException {
		ps.cancel();
	}

	/**
	 * @throws java.sql.SQLException
	 */
	public void clearBatch() throws SQLException {
		ps.clearBatch();
	}

	/**
	 * @throws java.sql.SQLException
	 */
	public void clearWarnings() throws SQLException {
		ps.clearWarnings();
	}

	/**
	 * @param sql
	 * @return
	 * @throws java.sql.SQLException
	 */
	public boolean execute(String sql) throws SQLException {
		return ps.execute(sql);
	}

	/**
	 * @param sql
	 * @param autoGeneratedKeys
	 * @return
	 * @throws java.sql.SQLException
	 */
	public boolean execute(String sql, int autoGeneratedKeys)
		throws SQLException {
		return ps.execute(sql, autoGeneratedKeys);
	}

	/**
	 * @param sql
	 * @param columnIndexes
	 * @return
	 * @throws java.sql.SQLException
	 */
	public boolean execute(String sql, int[] columnIndexes)
		throws SQLException {
		return ps.execute(sql, columnIndexes);
	}

	/**
	 * @param sql
	 * @param columnNames
	 * @return
	 * @throws java.sql.SQLException
	 */
	public boolean execute(String sql, String[] columnNames)
		throws SQLException {
		return ps.execute(sql, columnNames);
	}

	/**
	 * @return
	 * @throws java.sql.SQLException
	 */
	public int[] executeBatch() throws SQLException {
		return ps.executeBatch();
	}

	/**
	 * @param sql
	 * @return
	 * @throws java.sql.SQLException
	 */
	public ResultSet executeQuery(String sql) throws SQLException {
		return new ResultSetProxy(ps.executeQuery(sql), this);
	}

	/**
	 * @param sql
	 * @return
	 * @throws java.sql.SQLException
	 */
	public int executeUpdate(String sql) throws SQLException {
		return ps.executeUpdate(sql);
	}

	/**
	 * @param sql
	 * @param autoGeneratedKeys
	 * @return
	 * @throws java.sql.SQLException
	 */
	public int executeUpdate(String sql, int autoGeneratedKeys)
		throws SQLException {
		return ps.executeUpdate(sql, autoGeneratedKeys);
	}

	/**
	 * @param sql
	 * @param columnIndexes
	 * @return
	 * @throws java.sql.SQLException
	 */
	public int executeUpdate(String sql, int[] columnIndexes)
		throws SQLException {
		return ps.executeUpdate(sql, columnIndexes);
	}

	/**
	 * @param sql
	 * @param columnNames
	 * @return
	 * @throws java.sql.SQLException
	 */
	public int executeUpdate(String sql, String[] columnNames)
		throws SQLException {
		return ps.executeUpdate(sql, columnNames);
	}

	/**
	 * @return
	 * @throws java.sql.SQLException
	 */
	public Connection getConnection() throws SQLException {
		return ps.getConnection();
	}

	/**
	 * @return
	 * @throws java.sql.SQLException
	 */
	public int getFetchDirection() throws SQLException {
		return ps.getFetchDirection();
	}

	/**
	 * @return
	 * @throws java.sql.SQLException
	 */
	public int getFetchSize() throws SQLException {
		return ps.getFetchSize();
	}

	/**
	 * @return
	 * @throws java.sql.SQLException
	 */
	public ResultSet getGeneratedKeys() throws SQLException {
		return new ResultSetProxy(ps.getGeneratedKeys(), this);
	}

	/**
	 * @return
	 * @throws java.sql.SQLException
	 */
	public int getMaxFieldSize() throws SQLException {
		return ps.getMaxFieldSize();
	}

	/**
	 * @return
	 * @throws java.sql.SQLException
	 */
	public int getMaxRows() throws SQLException {
		return ps.getMaxRows();
	}

	/**
	 * @return
	 * @throws java.sql.SQLException
	 */
	public boolean getMoreResults() throws SQLException {
		return ps.getMoreResults();
	}

	/**
	 * @param current
	 * @return
	 * @throws java.sql.SQLException
	 */
	public boolean getMoreResults(int current) throws SQLException {
		return ps.getMoreResults(current);
	}

	/**
	 * @return
	 * @throws java.sql.SQLException
	 */
	public int getQueryTimeout() throws SQLException {
		return ps.getQueryTimeout();
	}

	/**
	 * @return
	 * @throws java.sql.SQLException
	 */
	public ResultSet getResultSet() throws SQLException {
		return new ResultSetProxy(ps.getResultSet(), this);
	}

	/**
	 * @return
	 * @throws java.sql.SQLException
	 */
	public int getResultSetConcurrency() throws SQLException {
		return ps.getResultSetConcurrency();
	}

	/**
	 * @return
	 * @throws java.sql.SQLException
	 */
	public int getResultSetHoldability() throws SQLException {
		return ps.getResultSetHoldability();
	}

	/**
	 * @return
	 * @throws java.sql.SQLException
	 */
	public int getResultSetType() throws SQLException {
		return ps.getResultSetType();
	}

	/**
	 * @return
	 * @throws java.sql.SQLException
	 */
	public int getUpdateCount() throws SQLException {
		return ps.getUpdateCount();
	}

	/**
	 * @return
	 * @throws java.sql.SQLException
	 */
	public SQLWarning getWarnings() throws SQLException {
		return ps.getWarnings();
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#hashCode()
	 */
	public int hashCode() {
		return ps.hashCode();
	}

	/**
	 * @param name
	 * @throws java.sql.SQLException
	 */
	public void setCursorName(String name) throws SQLException {
		ps.setCursorName(name);
	}

	/**
	 * @param enable
	 * @throws java.sql.SQLException
	 */
	public void setEscapeProcessing(boolean enable) throws SQLException {
		ps.setEscapeProcessing(enable);
	}

	/**
	 * @param direction
	 * @throws java.sql.SQLException
	 */
	public void setFetchDirection(int direction) throws SQLException {
		ps.setFetchDirection(direction);
	}

	/**
	 * @param rows
	 * @throws java.sql.SQLException
	 */
	public void setFetchSize(int rows) throws SQLException {
		ps.setFetchSize(rows);
	}

	/**
	 * @param max
	 * @throws java.sql.SQLException
	 */
	public void setMaxFieldSize(int max) throws SQLException {
		ps.setMaxFieldSize(max);
	}

	/**
	 * @param max
	 * @throws java.sql.SQLException
	 */
	public void setMaxRows(int max) throws SQLException {
		ps.setMaxRows(max);
	}

	/**
	 * @param seconds
	 * @throws java.sql.SQLException
	 */
	public void setQueryTimeout(int seconds) throws SQLException {
		ps.setQueryTimeout(seconds);
	}

	public boolean isClosed() throws SQLException {
		return ps.isClosed();
	}

	public boolean isPoolable() throws SQLException {
		return ps.isPoolable();
	}

	public boolean isWrapperFor(Class<?> iface) throws SQLException {
		return ps.isWrapperFor(iface);
	}

	public void setPoolable(boolean poolable) throws SQLException {
		ps.setPoolable(poolable);
	}

	public <T> T unwrap(Class<T> iface) throws SQLException {
		return ps.unwrap(iface);
	}

}
